// subPages/mine/health/health.js
import * as echarts from '../../../ec-canvas/echarts';
var util =  require('../../../utils/healthUtil.js');
var navListJson = require('../../../data/navListJson');
var indexJson = require('../../../data/indexJson');
let LineChart1 = null
let LineChart2 = null
let LineChart3 = null
let LineChart4 = null
let LineChart5 = null
let LineChart6 = null
let LineChart7 = null
let LineChart8 = null
let LineChart9 = null
let LineChart10 = null
let LineChart11 = null

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ec1: {
      // lazyLoad: true // 延迟加载
    },
    ec2: {
      // lazyLoad: true // 延迟加载
    },
    ec3: {
      // lazyLoad: true // 延迟加载
    },
    ec4: {
      // lazyLoad: true // 延迟加载
    },
    ec5: {
      // lazyLoad: true // 延迟加载
    },
    ec6: {
      // lazyLoad: true // 延迟加载
    },
    ec7: {
      // lazyLoad: true // 延迟加载
    },
    ec8: {
      // lazyLoad: true // 延迟加载
    },
    ec9: {
      // lazyLoad: true // 延迟加载
    },
    ec10: {
      // lazyLoad: true // 延迟加载
    },
    ec11: {
      // lazyLoad: true // 延迟加载
    },
    current: 0,
    currentTab1: 0,
    currentTab2: 0,
    currentTab3: 0,    
    navScrollLeft: 0,
    scalesNavList: navListJson.scalesNavList,
    bloodFatNavList: navListJson.bloodFatNavList,
    sugarNavList: navListJson.sugarNavList,
    navList:[{nav: '个人数据',id: ''}],
    tipTxt: {
      tipTxt: '暂无测量数据',
      tipImg: '/resources/healthData/index/noData.png'
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: (res) => {
        //创建节点选择器
        this.setData({
          windowWidth: res.windowWidth
        })
      },
    })
    that.setData({
      date: util.setTime(new Date())
    })
    if (!app.globalData.userInfo) {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      app.userInfoReadyCallback = res => {
        if (res) {
          that.setData({
            userInfo: res.userInfo
          });
        }
      }
    }else{
      that.setData({
        userInfo: app.globalData.userInfo
      })
    }
    if(app.globalData.userId){
      that.setData({
        userId: app.globalData.userId
      })
      that.getInfo(app.globalData.userId)
      that.getData(app.globalData.userId)
    }else{
      app.userIdCallback = userId => {
        if (userId != '') {
          that.setData({
            userId: userId
          });
          that.getInfo(userId)
          that.getData(userId)
        }
      }
    }
  },

  //授权登录
  unLoginBtn:function(){
    var that = this
    if(app.globalData.userInfo){
      that.setData({
        userInfo: app.globalData.userInfo
      })
    }else{
      let isLogin = app.globalData.userId?true:false 
      //未授权
      wx.navigateTo({
        url: '/pages/authorizedLogin/authorizedLogin?isLogin='+ isLogin,
      })
    }
  },

  //获得关系
  getInfo:function(userId){
    var that = this
    wx.request({
      url: app.globalData.apiUrl +'/get_fid',
      data: {
        user_id: userId
      },
      method: 'get',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        // console.log(res)
        if(res.data.length!=0){
          let navList = []
          for(var i in res.data){
            let userId = ''
            if(res.data[i].type == '1'){
              //长辈
              userId = res.data[i].fid
            }else if(res.data[i].type == '2'){
              //晚辈
              userId = res.data[i].user_id
            }
            let nav = {
              nav: res.data[i].gx + '数据',
              id: userId
            }
            navList.push(nav)
          }
          let list = that.data.navList.concat(navList)
          that.setData({
            navList: list,
            isFamily: true
          })
        }else{
          that.setData({
            isFamily: false
          })
        }
      },
      fail: function (res) {
        console.log("失败",res);
      }
    })
  },

  //选择导航栏
  switchNavList(event){
    var that = this
    var cur = event.currentTarget.dataset.current;
    if (that.data.current == cur) {
      return false;
    } else {
      that.setData({
        current: cur
      })
      let userId = that.data.navList[cur].id == ''?that.data.userId:that.data.navList[cur].id
      this.getData(userId)
    }
  },

  //获得数据
  getData:function(userId){
    var that = this
    wx.request({
      url: app.globalData.apiUrl +'/user_word',
      data: {
        userid: userId
      },
      method: 'get',
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        console.log(res)
        if(res.data.code == '200'){
          that.getBodyAge(res.data.data.tzc);
          that.getBodyFatScales(res.data.data.tzc);
          // that.getSport(res.data.data.sport);
          that.getPressure(res.data.data.blood);
          that.getBooldFat(res.data.data.sugarfat);
          that.getSugar(res.data.data.xuetang)
        }else{
          util.showModal('提示','数据异常')
          return;
        }
      },
      fail: function (res) {
        console.log("失败",res);
      }
    })
  },

  //生理年龄
  getBodyAge:function(list){
    var that = this
    if(list.length!=0){
      let badyAgeList = []
      let badyAgeTimeList = []
      for(var i in list){
        badyAgeList.push(list[i].bodyage?list[i].bodyage:0)
        badyAgeTimeList.push(list[i].createtime)
      }
      that.setData({
        badyAgeList: badyAgeList,
        badyAgeTimeList: badyAgeTimeList,
        isBodyAge: true
      })
      that.linechartsComponnet1 = that.selectComponent('#mychartLine1');
      LineChart1 = null
      that.getLineGraphData1();  //创建图表
    }else{
      that.setData({
        isBodyAge: false,
      })
    }
  },

  //生理年龄线图表
  getLineGraphData1:function(){
    var that = this
    if (!LineChart1){
      that.init_LineEcharts1(); //初始化图表
    }else{
      that.setLineOption1(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts1: function () {
    var that = this
    that.linechartsComponnet1.init((canvas, width, height) => {
      // 初始化图表
      LineChart1 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart1.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption1();
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart1;
    });
  },

  setLineOption1: function () {
    LineChart1.clear();  // 清除
    LineChart1.setOption(this.getLineOption1());  //获取新数据
  },

  //设置折线图表
  getLineOption1: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:30,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.badyAgeTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value + '岁'
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.badyAgeTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.badyAgeList
      }]
    };
    LineChart1.hideLoading()
    return option;
  },

  //体脂秤
  getBodyFatScales:function(list){
    var that = this
    if(list.length!=0){
      let ScalesTimeList = []
      let bmiList = []//bmi
      let bodyfatList = []//体脂率
      let proteinList = []//蛋白质
      let bmrList = []//bmr
      let musclemassList = []//肌肉量
      let visceralfatrateList = []//内脏脂肪
      let watercontentList = []//水分率
      let skeletoncontentList = []//骨矿含量
      for(var i in list){
        ScalesTimeList.push(list[i].createtime)
        bmiList.push(list[i].bmi?list[i].bmi:0)
        bodyfatList.push(list[i].bodyfat?list[i].bodyfat:0)
        proteinList.push(list[i].protein?list[i].protein:0)
        bmrList.push(list[i].bmrList?list[i].bmrList:0)
        musclemassList.push(list[i].musclemass?list[i].musclemass:0)
        visceralfatrateList.push(list[i].visceralfatrate?list[i].visceralfatrate:0)
        watercontentList.push(list[i].watercontent?list[i].watercontent:0)
        skeletoncontentList.push(list[i].skeletoncontent?list[i].skeletoncontent:0)
      }
      that.setData({
        ScalesTimeList: ScalesTimeList,
        bmiList: bmiList,
        bodyfatList: bodyfatList,
        proteinList: proteinList,
        bmrList: bmrList,
        musclemassList: musclemassList,
        visceralfatrateList: visceralfatrateList,
        watercontentList: watercontentList,
        skeletoncontentList: skeletoncontentList,
        isBodyFatScales: true
      })
      that.linechartsComponnet2 = that.selectComponent('#mychartLine2');   
      LineChart2 = null
      that.getLineGraphData2(that.data.bmiList);  //创建图表
    }else{
      that.setData({
        isBodyFatScales: false
      })
    }
  },

  //线图表
  getLineGraphData2:function(data){
    if(data == null) return;
    var that = this
    if (!LineChart2){
      that.init_LineEcharts2(data); //初始化图表
    }else{
      that.setLineOption2(data); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts2: function (data) {
    var that = this
    that.linechartsComponnet2.init((canvas, width, height) => {
      // 初始化图表
      LineChart2 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart2.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption2(data);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart2;
    });
  },

  setLineOption2: function (data) {
    LineChart2.clear();  // 清除
    LineChart2.setOption(this.getLineOption2(data));  //获取新数据
  },

  //设置折线图表
  getLineOption2: function (data) {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:30,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.ScalesTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(data),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          }
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(246,246,246,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data:data
      }]
    };
    LineChart2.hideLoading()
    return option;
  },

  //选择导航栏
  switchNav(event){
    var that = this
    var cur = event.currentTarget.dataset.current; 
    //每个tab选项宽度占1/5
    var singleNavWidth = that.data.windowWidth / 5;
    //tab选项居中                            
    that.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (that.data.currentTab1 == cur) {
      return false;
    } else {
      that.setData({
        currentTab1: cur
      })
      if(that.data.isBodyFatScales){
        that.setEchartsData(cur)
      }
    }
  },

  //给图表赋值
  setEchartsData:function(cur){
    var that = this
    switch (cur) {
      case 0:
        //bmi
        that.getLineGraphData2(that.data.bmiList);
        break;
      case 1:
        //体脂率
        that.getLineGraphData2(that.data.bodyfatList);
        break;
      case 2:
        //蛋白质
        that.getLineGraphData2(that.data.proteinList);
        break;
      case 3:
        //基础代谢
        that.getLineGraphData2(that.data.bmrList);
        break;
      case 4:
        //肌肉量
        that.getLineGraphData2(that.data.musclemassList);
        break;
      case 5:
        //内脏脂肪
        that.getLineGraphData2(that.data.visceralfatrateList);
        break;
      case 6:
        //水分率
        that.getLineGraphData2(that.data.watercontentList);
        break;
      case 7:
        //骨矿含量
        that.getLineGraphData2(that.data.skeletoncontentList);
        break;
    }
  },

  //运动记录
  getSport:function(list){
    var that = this
    if(list.length!=0){
      let sportList = []
      let sportTimeList = []
      for(var i in list){
        sportList.push(list[i].num?list[i].num:0)
        sportTimeList.push(list[i].date)
      }
      that.setData({
        sportList: sportList,
        sportTimeList: sportTimeList,
        isSport: true
      })
      that.linechartsComponnet3 = that.selectComponent('#mychartLine3');
      LineChart3 = null
      that.getLineGraphData3();  //创建图表
    }else{
      that.setData({
        isSport: false,
      })
    }
  },

  //线图表
  getLineGraphData3:function(){
    var that = this
    if (!LineChart1){
      that.init_LineEcharts3(); //初始化图表
    }else{
      that.setLineOption3(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts3: function () {
    var that = this
    that.linechartsComponnet3.init((canvas, width, height) => {
      // 初始化图表
      LineChart3 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart3.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption3();
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart3;
    });
  },

  setLineOption3: function () {
    LineChart3.clear();  // 清除
    LineChart3.setOption(this.getLineOption3());  //获取新数据
  },

  //设置折线图表
  getLineOption3: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:30,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.sportTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value + '步'
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.sportTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.sportList
      }]
    };
    LineChart3.hideLoading()
    return option;
  },

  //血压
  getPressure:function(list){
    var that = this
    if(list.length!=0){
      var pressureList = indexJson.pressureList3
      for(let j in pressureList)
      {
        switch (pressureList[j].index) {
          case 1:
            pressureList[j].data = list[0].height
            break;
          case 2:
            pressureList[j].data = list[0].low
            break;
          case 3:
            pressureList[j].data = list[0].heart
            break;
        }
      }
      let heightList = []
      let lowList = []
      let heartList = []
      let pressureTime = []
      for(var i in list){
        pressureTime.push(list[i].createtime)
        heightList.push(list[i].height)
        lowList.push(list[i].low)
        heartList.push(list[i].heart)
      }
      that.setData({
        pressureList: pressureList,
        heightList: heightList,
        lowList: lowList,
        heartList: heartList,
        pressureTime: pressureTime,
        isPressure: true
      })
      that.linechartsComponnet4 = that.selectComponent('#mychartLine4');
      LineChart4 = null
      that.getLineGraphData4();  //创建图表
    }else{
      that.setData({
        isPressure: false,
        pressureList: [],
      })
    }
  },

  //线图表
  getLineGraphData4:function(){
    var that = this
    if (!LineChart4){
      that.init_LineEcharts4(); //初始化图表
    }else{
      that.setLineOption4(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts4: function () {
    var that = this
    that.linechartsComponnet4.init((canvas, width, height) => {
      // 初始化图表
      LineChart4 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart4.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption4();
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart4;
    });
  },

  setLineOption4: function () {
    LineChart4.clear();  // 清除
    LineChart4.setOption(this.getLineOption4());  //获取新数据
  },

  //设置折线图表
  getLineOption4: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:30,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.pressureTime,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.pressureTime),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'高压',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        data: that.data.heightList
      },{
        name:'低压',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#1360fe',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(19,96,254,0.5)'
          }
        },
        data: that.data.lowList
      },{
        name:'心率',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#d35757',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(211,87,87,0.5)'
          }
        },
        data: that.data.heartList
      }]
    };
    LineChart4.hideLoading()
    return option;
  },

  //血脂
  getBooldFat:function(list){
    var that = this
    if(list.length!=0){
      let cholesterolList = [] //总胆固醇
      let glycerolList = [] //甘油三酯
      let uricList = [] //尿酸
      let hdlList = [] //高密度
      let ldlList = [] //低密度
      let booldFatTimeList = [] // 时间
      for(var i in list){
        booldFatTimeList.push(list[i].date)
        cholesterolList.push(list[i].cholesterol)
        glycerolList.push(list[i].glycerol)
        uricList.push(list[i].uric)
        hdlList.push(list[i].hdl)
        ldlList.push(list[i].ldl)
      }
      that.setData({
        isBloodFat: true,
        cholesterolList: cholesterolList,
        glycerolList: glycerolList,
        uricList: uricList,
        hdlList: hdlList,
        ldlList: ldlList,
        booldFatTimeList: booldFatTimeList,
        eName: '总胆固醇',
        ePadding: [0,0,0,48],
      })
      that.linechartsComponnet5 = that.selectComponent('#mychartLine5');   
      LineChart5 = null
      that.getLineGraphData5(that.data.cholesterolList);  //创建图表
    }else{
      that.setData({
        isBloodFat: false
      })
    }
  },

  //线图表
  getLineGraphData5:function(data){
    if(data == null) return;
    var that = this
    if (!LineChart5){
      that.init_LineEcharts5(data); //初始化图表
    }else{
      that.setLineOption5(data); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts5: function (data) {
    var that = this
    that.linechartsComponnet5.init((canvas, width, height) => {
      // 初始化图表
      LineChart5 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart5.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption5(data);
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart5;
    });
  },

  setLineOption5: function (data) {
    LineChart5.clear();  // 清除
    LineChart5.setOption(this.getLineOption5(data));  //获取新数据
  },

  //设置折线图表
  getLineOption5: function (data) {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.booldFatTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: that.data.eName,
        nameLocation: 'end',
        nameGap: 25,
        nameTextStyle:{
          color: '#76ebdc',
          padding: that.data.ePadding,
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(data),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          }
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            formatter:function(params){
              return params.data;
            }
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(246,246,246,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data:data
      }]
    };
    LineChart5.hideLoading()
    return option;
  },

  //选择导航栏
  switchNav2(event){
    var that = this
    var cur = event.currentTarget.dataset.current;
    if (that.data.currentTab2 == cur) {
      return false;
    } else {
      that.setData({
        currentTab2: cur
      })
      if(that.data.isBloodFat){
        that.setEchartsData2(cur)        
      }
    }
  },

  //给图表赋值
  setEchartsData2:function(cur){
    var that = this
    switch (cur) {
      case 0:
        //总胆固醇
        that.setData({
          eName: '总胆固醇',
          ePadding: [0,0,0,48],
        })
        that.getLineGraphData5(that.data.cholesterolList);
        break;
      case 1:
        //总胆固醇
        that.setData({
          eName: '甘油三酯',
          ePadding: [0,0,0,48],
        })
        that.getLineGraphData5(that.data.glycerolList);
        break;
      case 2:
        //甘油三酯
        that.setData({
          eName: '尿酸',
          ePadding: [0,0,0,24],
        })
        that.getLineGraphData5(that.data.uricList);
        break;
      case 3:
        //HDL
        that.setData({
          eName: 'HDL',
          ePadding: [0,0,0,26],
        })
        that.getLineGraphData5(that.data.hdlList);
        break;
      case 4:
        //LDL
        that.setData({
          eName: 'LDL',
          ePadding: [0,0,0,26],
        })
        that.getLineGraphData5(that.data.ldlList);
        break;
    }
  },

  //获得血糖数据
  getSugarData:function(list){
    var that = this
    var sugarList = indexJson.bloodSugarList3
    if(list.one.length!=0){
      sugarList[0].data = list.one[0].blood?list.one[0].blood:0        
    }else{
      sugarList[0].data = 0
    }
    if(list.two.length!=0){
      sugarList[1].data = list.two[0].blood?list.two[0].blood:0
    }else{
      sugarList[1].data = 0
    }
    if(list.three.length!=0){
      sugarList[2].data = list.three[0].blood?list.three[0].blood:0
    }else{
      sugarList[2].data = 0
    }
    if(list.four.length!=0){
      sugarList[3].data = list.four[0].blood?list.four[0].blood:0
    }else{
      sugarList[3].data = 0
    }
    if(list.five.length!=0){
      sugarList[4].data = list.five[0].blood?list.five[0].blood:0
    }else{
      sugarList[4].data = 0
    }
    if(list.six.length!=0){
      sugarList[5].data = list.six[0].blood?list.six[0].blood:0
    }else{
      sugarList[5].data = 0
    }
    that.setData({
      dataList: sugarList,
    })
  },

  //血糖
  getSugar:function(list){
    var that = this
    if(list.length != 0){
      that.getSugarData(list)
      let beforeBreakfastList = []
      let afterBreakfastList = []
      let beforeLunchList = []
      let afterLunchList = []
      let beforeDinnerList = []
      let afterDinnerList = []
      let beforeBreakfastTimeList = []
      let afterBreakfastTimeList = []      
      let beforeLunchTimeList = []
      let afterLunchTimeList = []
      let beforeDinnerTimeList = []
      let afterDinnerTimeList = []
      let breakfastTimeList = []
      let lunchTimeList = []
      let dinnerTimeList = []
      // 早餐前      
      if(list.one.length!=0){
        for(let i in list.one){
          beforeBreakfastList.push(list.one[i].blood)
          beforeBreakfastTimeList.push(list.one[i].date)
        }
        that.setData({
          isBeforeBreakfastData: true,
          beforeBreakfastList: beforeBreakfastList,
          beforeBreakfastTimeList: beforeBreakfastTimeList,
        })
        that.linechartsComponnet6 = that.selectComponent('#mychartLine6');
        LineChart6 = null
        that.getLineGraphData6();
      }else{
        that.setData({
          isBeforeBreakfastData: false
        })
      }
      // 早餐后
      if(list.two.length != 0){
        for(let i in list.two){
          afterBreakfastList.push(list.two[i].blood)
          afterBreakfastTimeList.push(list.two[i].date)
        }
        that.setData({
          isAfterBreakfastData: true,
          afterBreakfastList: afterBreakfastList,
          afterBreakfastTimeList: afterBreakfastTimeList
        })
        that.linechartsComponnet7 = that.selectComponent('#mychartLine7');
        LineChart7 = null
        that.getLineGraphData7();
      }else{
        that.setData({
          isAfterBreakfastData: false
        })
      }
      // 午餐前
      if(list.three.length != 0){
        for(let i in list.three){
          beforeLunchList.push(list.three[i].blood)
          beforeLunchTimeList.push(list.three[i].date)
        }
        that.setData({
          isBeforeLunchData: true,
          beforeLunchList: beforeLunchList,
          beforeLunchTimeList: beforeLunchTimeList     
        })
        that.linechartsComponnet8 = that.selectComponent('#mychartLine8');
        LineChart8 = null
        that.getLineGraphData8();
      }else{
        that.setData({
          isBeforeLunchData: false
        })
      }
      // 午餐后      
      if(list.four.length != 0){
        for(let i in list.four){
          afterLunchList.push(list.four[i].blood)
          afterLunchTimeList.push(list.four[i].date)
        }
        that.setData({
          isAfterLunchData: true,
          afterLunchList: afterLunchList,
          afterLunchTimeList: afterLunchTimeList   
        })
        that.linechartsComponnet9 = that.selectComponent('#mychartLine9');
        LineChart9 = null
        that.getLineGraphData9();
      }else{
        that.setData({
          isAfterLunchData: false
        })
      }
      // 晚餐前
      if(list.five.length != 0){
        for(let i in list.five){
          beforeDinnerList.push(list.five[i].blood)
          beforeDinnerTimeList.push(list.five[i].date)
        }
        that.setData({
          isBeforeDinnerData: true,
          beforeDinnerList: beforeDinnerList,
          beforeDinnerTimeList: beforeDinnerTimeList,
        })
        that.linechartsComponnet10 = that.selectComponent('#mychartLine10');
        LineChart10 = null
        that.getLineGraphData10();
      }else{
        that.setData({
          isBeforeDinnerData: false
        })
      }
      // 晚餐后
      if(list.six.length != 0){
        for(let i in list.six){
          afterDinnerList.push(list.six[i].blood)
          afterDinnerTimeList.push(list.six[i].date)
        }
        that.setData({
          isAfterDinnerData: true,
          afterDinnerList: afterDinnerList,
          afterDinnerTimeList: afterDinnerTimeList,
        })
        that.linechartsComponnet11 = that.selectComponent('#mychartLine11');
        LineChart11 = null
        that.getLineGraphData11();
      }else{
        that.setData({
          isAfterDinnerData: false
        })
      }
      that.setData({
        arrList : list
      })
    }else{
      that.setData({
        dataList: indexJson.bloodSugarList2,
      })
    }
  },

  //早餐前
  //获取异常信息
  getErroyData:function(type,time){
    var that = this
    var list = that.data.arrList
    if(type == 1){
      for(let i in list.one){
        if(time == list.one[i].date && list.one[i].content){
          that.setData({
            breakfastText: list.one[i].content,
            breakfastETime: time
          })
          return true          
        }
      }
    }
    if(type == 2){
      for(let i in list.two){
        if(time == list.two[i].date && list.two[i].content){
          that.setData({
            breakfastText: list.two[i].content,
            breakfastETime: time
          })
          return true
        }
      }
    }
    if(type == 3){
      for(let i in list.three){
        if(time == list.three[i].date && list.three[i].content){
          that.setData({
            lunchText: list.three[i].content,
            lunchETime: time
          })
          return true
        }
      }
    }
    if(type == 4){
      for(let i in list.four){
        if(time == list.four[i].date && list.four[i].content){
          that.setData({
            lunchText: list.four[i].content,
            lunchETime: time
          })
          return true
        }
      }
    }
    if(type == 5){
      for(let i in list.five){
        if(time == list.five[i].date && list.five[i].content){
          that.setData({
            dinnerText: list.five[i].content,
            dinnerETime: time
          })
          return true
        }
      }
    }
    if(type == 6){
      for(let i in list.six){
        if(time == list.six[i].date && list.six[i].content){
          that.setData({
            dinnerText: list.six[i].content,
            dinnerETime: time
          })
          return true
        }
      }
    }
    return false
  },

  //线图表
  getLineGraphData6:function(){
    var that = this
    if (!LineChart6){
      that.init_LineEcharts6(); //初始化图表
    }else{
      that.setLineOption6(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts6: function () {
    var that = this
    that.linechartsComponnet6.init((canvas, width, height) => {
      // 初始化图表
      LineChart6 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart6.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption6();
      LineChart6.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[0].data"
        that.setData({
          breakfastTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(1,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart6;
    });
  },

  setLineOption6: function () {
    LineChart6.clear();  // 清除
    LineChart6.setOption(this.getLineOption6());  //获取新数据
  },

  //设置折线图表
  getLineOption6: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.beforeBreakfastTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '早餐前',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.beforeBreakfastTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'早餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeBreakfastList
      }]
    };
    LineChart6.hideLoading()
    return option;
  },

  //早餐后
  //线图表
  getLineGraphData7:function(){
    var that = this
    if (!LineChart7){
      that.init_LineEcharts7(); //初始化图表
    }else{
      that.setLineOption7(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts7: function () {
    var that = this
    that.linechartsComponnet7.init((canvas, width, height) => {
      // 初始化图表
      LineChart7 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart7.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption7();
      LineChart7.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[1].data"        
        that.setData({
          breakfastTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(2,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart7;
    });
  },

  setLineOption7: function () {
    LineChart7.clear();  // 清除
    LineChart7.setOption(this.getLineOption7());  //获取新数据
  },

  //设置折线图表
  getLineOption7: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.afterBreakfastTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '早餐后',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.afterBreakfastTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'早餐后',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterBreakfastList
      }]
    };
    LineChart7.hideLoading()
    return option;
  },

  // 午餐前
  // 线图表8
  getLineGraphData8:function(){
    var that = this
    if (!LineChart8){
      that.init_LineEcharts8(); //初始化图表
    }else{
      that.setLineOption8(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts8: function () {
    var that = this
    that.linechartsComponnet8.init((canvas, width, height) => {
      // 初始化图表
      LineChart8 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart8.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption8();
      LineChart8.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[2].data"
        that.setData({
          lunchTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(3,e.name)
        // console.log(isErroy)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart8;
    });
  },

  setLineOption8: function () {
    LineChart8.clear();  // 清除
    LineChart8.setOption(this.getLineOption8());  //获取新数据
  },

  //设置折线图表
  getLineOption8: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },        
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.beforeLunchTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '午餐前',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.beforeLunchTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'午餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeLunchList
      }]
    };
    LineChart8.hideLoading()
    return option;
  },

  //午餐后
  // 线图表9
  getLineGraphData9:function(){
    var that = this
    if (!LineChart9){
      that.init_LineEcharts9(); //初始化图表
    }else{
      that.setLineOption9(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts9: function () {
    var that = this
    that.linechartsComponnet9.init((canvas, width, height) => {
      // 初始化图表
      LineChart9 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart9.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption9();
      LineChart9.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[3].data"        
        that.setData({
          lunchTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(4,e.name)
        // console.log(isErroy)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart9;
    });
  },

  setLineOption9: function () {
    LineChart9.clear();  // 清除
    LineChart9.setOption(this.getLineOption9());  //获取新数据
  },

  //设置折线图表
  getLineOption9: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },        
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.afterLunchTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '午餐后',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.afterLunchTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'午餐后',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterLunchList
      }]
    };
    LineChart9.hideLoading()
    return option;
  },

  // 晚餐前
  //线图表10
  getLineGraphData10:function(){
    var that = this
    if (!LineChart10){
      that.init_LineEcharts10(); //初始化图表
    }else{
      that.setLineOption10(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts10: function () {
    var that = this
    that.linechartsComponnet10.init((canvas, width, height) => {
      // 初始化图表
      LineChart10 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart10.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption10();
      LineChart10.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[4].data"
        that.setData({
          dinnerTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(5,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart10;
    });
  },

  setLineOption10: function () {
    LineChart10.clear();  // 清除
    LineChart10.setOption(this.getLineOption10());  //获取新数据
  },

  //设置折线图表
  getLineOption10: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.beforeDinnerTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '晚餐前',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.beforeDinnerTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'晚餐前',
        type:'line',
        connectNulls: true,
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#fff',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(255,255,255,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.beforeDinnerList
      }]
    };
    LineChart10.hideLoading()
    return option;
  },

  //晚餐后
  //线图表11
  getLineGraphData11:function(){
    var that = this
    if (!LineChart11){
      that.init_LineEcharts11(); //初始化图表
    }else{
      that.setLineOption11(); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts11: function () {
    var that = this
    that.linechartsComponnet11.init((canvas, width, height) => {
      // 初始化图表
      LineChart11 = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart11.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption11();
      LineChart11.on('click',{seriesIndex: 0},function(e){
        // console.log(e)
        var data = "dataList[5].data"        
        that.setData({
          dinnerTime: e.name,
          [data]: e.data
        })
        var isErroy = that.getErroyData(6,e.name)
        if(isErroy){
          e.event.target.style.text = '异常血糖'
          e.event.target.style.fill = 'rgba(255,60,60,1)'
          e.event.target.style.stroke = 'rgba(255,60,60,0.5)'
          e.event.target.style.textFill = 'red'
        }
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart11;
    });
  },

  setLineOption11: function () {
    LineChart11.clear();  // 清除
    LineChart11.setOption(this.getLineOption11());  //获取新数据
  },

  //设置折线图表
  getLineOption11: function () {
    var that = this
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:50,
        x2:0,
        y2:0,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        show:true,
        boundaryGap:true,
        data : that.data.afterDinnerTimeList,
        axisLine:{
          show:true,
          lineStyle:{
            color: 'white',
            width: 1,
          }
        },
        axisTick:{
          show:false
        },
        axisLabel:{
          show:true,
          color: 'white',
          interval: 0,
          formatter: '{value}',
          formatter:function(value){
            return util.setTime15(value)
          }
        },
      },
      yAxis: {
        type: 'value',
        name: '晚餐后',
        nameLocation: 'end',
        nameGap: 25,
        connectNulls: true,
        nameTextStyle:{
          color: '#76ebdc',
          padding: [0,0,0,48],
        },
        boundaryGap:false,
        show:true,
        scale: false,
        splitNumber:2,
        axisLine:{
          show: false,
        },
        axisTick: {
          show: false,
        },
        splitLine:{
          show:true,
          lineStyle:{
            color: 'rgba(255,255,255,0.3)',
          }
        },
        axisLabel:{
          show: true,
          inside: true,
          verticalAlign: 'bottom',
          margin: 0,
          color: '#76ebdc',
          formatter:function(value,index){
            return value
          }
        },
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: util.dataZoom(that.data.afterDinnerTimeList),
          end: 100,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'晚餐后',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 12,
        itemStyle : {
          normal: {
            color: '#616161',
          },
        },
        emphasis:{
          label:{
            show: true,
            position: 'top',
            color: '#616161',
          },
          itemStyle:{
            borderWidth: 12,
            borderType:'solid',
            borderColor: 'rgba(97,97,97,0.5)'
          }
        },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [{
                offset: 0, color: 'rgba(255,255,255,0)' // 0% 处的颜色
            }, {
                offset: 1, color: 'rgba(255,255,255,0.2)' // 100% 处的颜色
            }],
            globalCoord: false // 缺省为 false
          }
        },
        data: that.data.afterDinnerList
      }]
    };
    LineChart11.hideLoading()
    return option;
  },

  //选择导航栏
  switchNav3(event){
    var that = this
    var cur = event.currentTarget.dataset.current;      
    if (that.data.currentTab3 == cur) {
      return false;
    } else {
      that.setData({
        currentTab3: cur
      })
      that.setEchartsData3(cur)
    }
  },

  //给图表赋值
  setEchartsData3:function(cur){
    var that = this
    switch (cur) {
      case 0:
        //早餐
        if(that.data.isBeforeBreakfastData){
          LineChart6 = null
          that.getLineGraphData6();
        }
        if(that.data.isAfterBreakfastData){
          LineChart7 = null
          that.getLineGraphData7();
        }
        break;
      case 1:
        //午餐
        if(that.data.isBeforeLunchData){
          LineChart8 = null
          that.getLineGraphData8();
        }
        if(that.data.isAfterLunchData){
          LineChart9 = null
          that.getLineGraphData9();
        }
        break;
      case 2:
        //晚餐
        if(that.data.isBeforeDinnerData){
          LineChart10 = null
          that.getLineGraphData10();
        }
        if(that.data.isAfterDinnerData){
          LineChart11 = null
          that.getLineGraphData11();
        }
        break;
    }
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    // return {
    //   title: '智慧社区',
    //   path: 'pages/index/index',
    //   success: function(res) {
    //     // res.shareTickets 
    //   },
    //   fail: function(res) {
    //       console.log(res)
    //   }
    // }
  }
})